<?php
/**
 * Created by PhpStorm.
 * User: rain
 * Date: 2018/4/7
 * Time: 下午1:40
 */

namespace App\Utils;

use App\Models\Orders;
use App\Models\SpringTestRecord;
use Illuminate\Support\Facades\Mail;

/**
 * https://blog.csdn.net/woqianduo/article/details/81024244
 * Class MailUtil
 * @package App\Utils
 */
class MailUtil
{

    public static function sendMail(SpringTestRecord $springTestRecord, $mail = '')
    {
        $orderCode = '';
        /** @var Orders $order */
        $order = Orders::find($springTestRecord->order_id);
        if (!empty($order)){
            $orderCode = $order->order_code;
        }

        $url = "https://xiaokedou.xkd100.com/h5/pages/spring/result?order_code={$orderCode}&record_id=" . $springTestRecord->id;
        $content = "亲爱的考生/家长，我们已为您生成了网页版的2022年春考志愿测评分析报告，其中通过网页就可以下载对应的报告。打开链接：{$url} 

有任何疑问可以联系老师微信：xulaoshi275";
        $title = '2021年春考评测报告';

        return Mail::raw($content, function ($message) use ($mail, $title){
            $message->to($mail)->subject($title);
            //$attachment = public_path('exports/中职校志愿模板.xlsx');
            //$message->attach($attachment, ['as' => '中职校志愿模板.xlsx']);
        });

        //        return Mail::send('email',['order'=>$springTestRecord], function ($message) use ($mail, $title){
        //            $message->to($mail)->subject($title);
        //            //$attachment = public_path('exports/中职校志愿模板.xlsx');
        //            //$message->attach($attachment, ['as' => '中职校志愿模板.xlsx']);
        //        });
    }


}
